package edu.gyc.objecthomework;/*
 * ConcertPromoter.java
 *
 * Created on February 15, 2007, 4:09 PM
 *
 * Solution to Project 8
 */

/**
 *
 * @author charleshoot
 */

import java.util.Scanner;

public class ConcertPromoter {


    private String bandName;
    private int capacity;
    private int ticketsSold;
    private double costPhone;
    private double costVenue;
    private double totalSales;
    private boolean salesAreByPhone;


    /**
     * initialize the instance
     */

    public void initialize(String band, int max, double costOverPhone, double costAtVenue) {
        bandName = band;
        capacity = max;
        ticketsSold = 0;
        costPhone = costOverPhone;
        costVenue = costAtVenue;
        totalSales = 0.0;
        salesAreByPhone = true;
    }


    public void doTicketSale(){
        System.out.println("How many tickets to sell? (Maximum " + getTicketsLeft() + ")");

        Scanner reader = new Scanner(System.in);
        int toSell = reader.nextInt();

        boolean saleCompleted = sellTickets(toSell);

        if(saleCompleted)
            System.out.println("The cost of the tickets is " + getSaleCost(toSell));
        else
            System.out.println("Sorry, unable to complete that sale");
    }

    public boolean sellTickets(int number){
        if(number > 0 && number <= getTicketsLeft()){
            ticketsSold += number;
            totalSales += getSaleCost(number);
            return true;
        } else {
            return false;
        }

    }

    public double getSaleCost(int number){
        double saleCost = number;
        if(salesAreByPhone)
            saleCost *= costPhone;
        else
            saleCost *= costVenue;
        return saleCost;
    }

    public void phoneSalesOver(){
        salesAreByPhone = false;
    }

    public int getTicketsSold(){
        return ticketsSold;
    }

    public int getTicketsLeft(){
        return capacity - ticketsSold;
    }

    public double getTotalSales(){
        return totalSales;
    }

    public boolean phoneSalesOnly(){
        return salesAreByPhone;
    }

    public String getSalesReport(){
        return "Sales for " + bandName + ":  Tickets sold: " + ticketsSold + " for " + totalSales;
    }





    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        ConcertPromoter concert = new ConcertPromoter();
        concert.initialize("The Ducks", 100, 10.00 , 12.00);
        System.out.println("Concert Promoter Sales Program started");

        Scanner reader = new Scanner(System.in);

        boolean done = false;

        while(!done){
            if(concert.phoneSalesOnly())
                System.out.println("Sell tickets (S), Change to venue sales (V), Finish selling (F)");
            else
                System.out.println("Sell tickets (S), Finish selling (F)");

            String response = reader.next();
            if(response.equals("F"))
                done = true;
            else if(response.equals("S"))
                concert.doTicketSale();
            else if(response.equals("V"))
                concert.phoneSalesOver();
            else {
                System.out.println("Sorry the response " + response + " was not valid.");
            }

            System.out.println("Tickets remaining: " + concert.getTicketsLeft());
        }
        System.out.println("Final report: " + concert.getSalesReport());


    }


}





